package tliasmanagement.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import tliasmanagement.pojo.Student;
import tliasmanagement.pojo.StudentQueryParam;

import java.util.List;

@Mapper
public interface StudentMapper {

    /**
     * 分页查询
     *
     * @param studentQueryParam 查询参数
     */
    public List<Student> getStudentByPage(StudentQueryParam studentQueryParam);

    /**
     * 新增学生
     *
     * @param student 新增的学生
     */
    @Insert("insert into student(name, no, gender, phone, id_card, is_college, address, degree, graduation_date, clazz_id, violation_count, violation_score, create_time, update_time) " +
            "values (#{name}, #{no}, #{gender}, #{phone}, #{idCard}, #{isCollege}, #{address}, #{degree}, #{graduationDate}, #{clazzId}, #{violationCount}, #{violationScore}, #{createTime}, #{updateTime})")
    void add(Student student);

    /**
     * 获取学生详情
     *
     * @param id 学生id
     * @return 学生详情
     */
    @Select("select s.*,c.id clazzId, c.name clazzName  from student as s " +
            "left join clazz as c on s.clazz_id = c.id " +
            "where s.id = #{id}")
    Student getDetailInfo(Integer id);

    /**
     * 修改学生信息
     *
     * @param student 修改的学生信息
     */
    @Update("update student set name = #{name}, no = #{no}, gender = #{gender}, phone = #{phone}, id_card = #{idCard}, is_college = #{isCollege}, address = #{address}, degree = #{degree}, graduation_date = #{graduationDate}, clazz_id = #{clazzId}, violation_count = #{violationCount}, violation_score = #{violationScore}, update_time = #{updateTime} " +
            "where id = #{id}" )
    void update(Student student);

    /**
     * 删除学生
     * @param ids 学生id列表
     */
    void delete(List<Integer> ids);
}
